<template>
  <div class="module_container">
    <div class="module_title">
      <div class="title_text">网格内企业统计</div>
    </div>
    <!-- <dv-loading v-if="loading">Loading...</dv-loading> -->
    <div class="content">
      <div class="sub_title">当前网格企业类型比例</div>
      <div flex="cross:center">
        <div class="l_circle" flex="cross:center main:center">
          <dv-active-ring-chart :config="config" style="width:300px;height:300px" />
          <!-- <p class="text">行业认证</p> -->
        </div>
        <ul class="flex_1 list_box">
          <li v-for="(item,index) in categoryOptions" :key="item.id" flex="main:justify">
            <span class="flex_1" flex="cross:center">
              <i :class="`circle_${index+1}`" />
              {{ item.category }}</span>
            <span style="width:150px;text-align:right;padding-right:40px">{{ item.num }}</span>
            <span style="width:60px">{{ transPercent(item.percent) }}</span>
          </li>
        </ul>
        <!-- <img src="@/assets/img_xinyong/module2/data_circle_bg.png" alt="" srcset=""> -->
      </div>

      <div class="sub_title"> 当前网格企业迁入迁出变化趋势</div>

      <div ref="bar" class="bar" />
      <div class="sub_title"> 当前网格新登记企业注册资本趋势</div>

      <div ref="bar1" class="bar1" />
      <div class="sub_title"> 企业税收趋势</div>

      <div ref="bar2" class="bar2" />

    </div>
  </div>
</template>

<script>
import { optionLine, optionLine1 } from './module1_option.js'
// import Charts from '@jiaminghi/charts'
import { listCategory, listTrendByMonth } from '@/api/community'
import Highcharts from '@/config/highCharts'
export default {
  data() {
    return {
      config: {
        data: [],
        lineWidth: 10
      },
      categoryOptions: [],
      policyList: [],
      policyCashByMonthList: [],
      loading: true,
      currYear: new Date().getFullYear() - 1
    }
  },
  created() {
    this.$eventBus.$on('changeCommunity', item => {
      this.getData(item.id)
    })
  },
  destroyed() {
    this.$eventBus.$off('changeCommunity')
  },
  methods: {
    getData(gridId) {
      Promise.all([listCategory({ gridId }), listTrendByMonth({ gridId, year: this.currYear })]).then(res => {
        const [categoryOptions, trendOptions] = res
        const retrendOptions = trendOptions.data.sort((a, b) => a.month - b.month)
        optionLine.xAxis[0].categories = retrendOptions.map(item => item.month + '月')
        optionLine1.xAxis[0].categories = retrendOptions.map(item => item.month + '月')
        optionLine.series[0].data = retrendOptions.map(item => item.registeredCapital)
        optionLine1.series[0].data = retrendOptions.map(item => item.inNum || 0)
        optionLine1.series[1].data = retrendOptions.map(item => item.outNum || 0)
        this.categoryOptions = categoryOptions.data
        // this.policyList = policyList.data
        this.config = {
          data: categoryOptions.data.map(item => ({
            name: item.category, value: item.num
          })),
          lineWidth: 10
        }
        this.$nextTick(() => {
          Highcharts.chart(this.$refs.bar1, optionLine)
          optionLine.series[0].data = retrendOptions.map(item => item.totalTax || 0)
          Highcharts.chart(this.$refs.bar2, optionLine)
          Highcharts.chart(this.$refs.bar, optionLine1)
          // new Charts(this.$refs.bar1).setOption(optionLine1)
          // new Charts(this.$refs.bar2).setOption(optionLine1)
          // this.loading = false
        })
      })
    }

  }
}

</script>

<style lang="scss" scoped>
.content {
  // margin-top: 20px;
  // position: relative;
  padding: 25px 40px;
  font-size: 28px;
  .sub_title {
    margin-top: 20px;
    margin-bottom: 20px;
    background: url("~@/assets/img_xinyong/module6/sub_title_bg.png") no-repeat;
    width: 520px;
    height: 58px;
    line-height: 58px;
    // padding:20px;
    padding-left: 70px;
    font-size: 28px;
  }
  & > .bar,
  & > .bar1,
  & > .bar2 {
    width: 100%;
    height: 350px;
    margin-bottom: 15px;
  }
  .legend_box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    position: relative;
    flex: 1;
    & > * {
      width: 48%;
      line-height: 64px;
      color: #bfdaff;
      background: url("~@/assets/img_qingqin/module2/card_bg.png") no-repeat;
      background-size: 100% 100%;
      text-align: center;
      padding: 0 10px;
      box-sizing: border-box;
      margin-bottom: 24px;
    }
  }
  & > .ranking {
    margin-bottom: 10px;
    color: #c0e6ff;
    & > *:first-child {
      width: 64px;
      height: 64px;
      text-align: center;
      line-height: 64px;
      background: url("~@/assets/img_qingqin/module2/rank_mark_normal_bg.png")
        no-repeat;
      background-size: 100% 100%;
      &.active {
        background: url("~@/assets/img_qingqin/module2/rank_mark_active_bg.png")
          no-repeat;
        background-size: 100% 100%;
      }
    }
    & > *:last-child {
      background: url("~@/assets/img_qingqin/module2/rank_data_bg.png")
        no-repeat;
      background-size: 100% 100%;
      width: 1020px;
      height: 64px;
      line-height: 64px;
      padding-left: 30px;
      &.active {
        background: url("~@/assets/img_qingqin/module2/rank_data_bg_active.png")
          no-repeat;
        background-size: 100% 100%;
      }
    }
  }
  .l_circle {
    background: url("~@/assets/img_xinyong/module2/data_circle_bg.png")
      no-repeat;
    background-size: cover;
    height: 280px;
    width: 280px;
    position: relative;
    .text {
      position: absolute;
      bottom: -50px;
      text-align: center;
      width: 100%;
    }
    // padding-bottom: 20px;
  }
  .list_box {
    color: #bfdaff;
    height: 320px;
    overflow: auto;
    & > * {
      background: url("~@/assets/img_qingqin/module1/data_bg.png") no-repeat;
      background-size: 100% 100%;
      padding: 20px;
      padding-right: 50px;
      &:not(:first-child) {
        margin-top: 3px;
        // padding:10px
      }
      i {
        width: 12px;
        height: 12px;
        border-radius: 50%;
        margin-right: 10px;
        &.circle_1 {
          background-image: linear-gradient(220deg, #fcbb43 1%, #f86720 100%);
        }
        &.circle_2 {
          background-image: linear-gradient(177deg, #30b3ff 13%, #223bff 92%);
        }
        &.circle_3 {
          background: #00e676;
        }
        &.circle_4 {
          background-image: linear-gradient(43deg, #8815f9 7%, #f959cf 95%);
        }
        &.circle_5 {
          background-image: linear-gradient(76deg, #ffffff 39%, #c0bebe 94%);
        }
      }
    }
  }
}
</style>
